package chai.ningning.dev;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/general/*")
public class GeneralServlet extends HttpServlet {

	private static final long serialVersionUID = -8457335322212911909L;

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");

		String uname = req.getParameter("username");
		String pword = req.getParameter("password");
		System.out.println(uname + pword);

		String method = req.getMethod();
		System.out.println(method);

		// 输出流之前，先设置 MIME 类型
		resp.setContentType("text/html ; charset=utf-8");
		
		// 在控制台（Console）中输出信息
		System.out.println( "general servlet : service" );
		
		// 获得可以向响应对象中输出数据的字符输出流
		PrintWriter out = resp.getWriter();
		
		// 向响应对象中输出HTML片段（最终发送到Web客户端）
		out.println("<h1 align='center'>I am a general servlet .</h1>");
		out.println("<h3 align='center'>request method ( HTTP action ) : " + method + " .</h3>");
	}

}
